package com.example.hotelapp.Adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.example.hotelapp.Activity.DetailActivity;
import com.example.hotelapp.Base.BaseRvAdapter;
import com.example.hotelapp.Base.BaseRvViewHolder;
import com.example.hotelapp.Bean.HomeIndexBean;
import com.example.hotelapp.R;
import com.example.hotelapp.Utils.AppNetConfig;
import com.shehuan.niv.NiceImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 首页列表适配器
 */
public class HomeAdapter extends BaseRvAdapter<HomeIndexBean.DataBean, HomeAdapter.HomeViewHolder> {

    public HomeAdapter(Context context, List<HomeIndexBean.DataBean> datas) {
        super(context, datas);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void onBindData(HomeViewHolder holder, HomeIndexBean.DataBean dataBean, int position) {
        holder.name.setText(dataBean.getHotelName());
        holder.level.setText(dataBean.getHotelLevel());
        holder.mark.setText(dataBean.getRemark());
        holder.Price.setText("" + (int) dataBean.getMinPrice());
        Glide.with(context).load(AppNetConfig.HotelImgUrl + dataBean.getHotelPicture()).into(holder.img);
        //传达参数
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DetailActivity.start(context, String.valueOf(dataBean.getId()),dataBean.getHotelName(),dataBean.getHotelPicture());
            }
        });

    }

    @NonNull
    @Override
    public HomeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_home, parent, false);
        return new HomeViewHolder(view);
    }

    public static class HomeViewHolder extends BaseRvViewHolder {
        @BindView(R.id.tt)
        NiceImageView img;
        @BindView(R.id.tv_title)
        TextView name;
        @BindView(R.id.tv_shuoming)
        TextView level;
        @BindView(R.id.tv_shuoming2)
        TextView mark;
        @BindView(R.id.tv_price)
        TextView Price;

        public HomeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}

